package com.lyc.servlet.admin;

import com.lyc.dao.CountryInfoDAO;
import com.lyc.dao.imp.CountryInfoDAOImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/admin/country-delete.let")
public class CountrydeleteServlet extends HttpServlet {

    private CountryInfoDAO dao = new CountryInfoDAOImpl();
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	request.setCharacterEncoding("UTF-8");
    	response.reset();
        response.setContentType("application/json;charset=UTF-8");
        
        try {
        	String code = request.getParameter("countryCode");
            try{
                dao.deleteById(code);
                response.getWriter().print("{\"ok\":true}");
            }catch (Exception ex){
                throw new ServletException("删除失败", ex);
            }
        }catch(Exception e) {
        	response.getWriter().print("{\"ok\":false,\"msg\":\""+e.getMessage()+"\"}");
        }
        
        response.flushBuffer();
    }
}
